package com.quanxi.qxaimain.dao.indicators;


import com.quanxi.qxaimain.common.datasource.datasourceAOP.annotation.DataSource;
import com.quanxi.qxaimain.common.datasource.datasourceAOP.enums.DataSourceEnum;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author lyx
 * @create 2021/3/25 10:10
 */

@Component
public interface indicatorsDataMapper {

   @DataSource(DataSourceEnum.DB1)
    @Select("select * from qxzsk_t_indicator_sql where ind_id=#{ind_id} or #{ind_id}=\"\"")  //参数为空 则查全部
    List<Map<String, Object>> find_indicators_sql(@Param("ind_id") String ind_id);


//    //选择不同的表
//    @DataSource(DataSourceEnum.DB1)
//    @Select("select * from ${tableName} where ind_id=#{ind_id} or #{ind_id}=\"\"")  //参数为空 则查全部
//    List<Map<String, Object>> find_indicators_sql_table(@Param("tableName") String tableName, @Param("ind_id") String ind_id);


//
//    @DataSource(DataSourceEnum.DB1)
//    @Select("select * from qxzsk_t_indicator_sql where ind_id=#{ind_id} or #{ind_id}=\"\" and model_name  like #{model_name}")  //参数为空 则查全部
//    List<Map<String, Object>> find_indicators_sql_report(@Param("ind_id") String ind_id, @Param("model_name") String model_name);






    //批量list  qxzsk_t_indicator_sql 去掉sql失败和未调试的指标
    @DataSource(DataSourceEnum.DB1)
    @Select({
            "<script>",
            "select * from ${tableName} where " +
                    "IFNULL(sql_detail_value,'') not REGEXP '失败' and\n" +
                    "IFNULL(sql_detail_value,'') not REGEXP '未调试' and\n" +
                    "IFNULL(sql_value,'') not REGEXP '失败' and\n" +
                    "IFNULL(sql_value,'') not REGEXP '未调试'  and " +
            " ind_id in ",
            "<foreach collection='indIdList' item='indIdList' open='(' separator=',' close=')'>",
            "#{indIdList}",
            "</foreach>",
            "</script>"
    })
     List<Map<String,Object>> find_indicators_sql_lists_ok(@Param("tableName") String tableName, @Param("indIdList") List<String> indIdList);











//sql执行
   // @DataSource(DataSourceEnum.DB5)
    @Select("${sqlStr}")
    List<LinkedHashMap<String, Object>> exec_sql(@Param(value = "sqlStr") String sqlStr);

    @Select("${sqlStr}")
    List<Map<String, Object>>  exec_sql_listmap(@Param(value = "sqlStr") String sqlStr);


    @DataSource(DataSourceEnum.DB1)
    @Select("${sqlStr}")
    List<LinkedHashMap<String, Object>>  exec_sql2(@Param(value = "sqlStr") String sqlStr);

    //关键词搜索
    @DataSource(DataSourceEnum.DB1)
    @Select("<script>"+
            "select * from  qxzsk_t_indicator_sql  WHERE 1 = 1 and model_name like #{model_name} "+
            "<if test='keywords!= null and keywords!=\"\"'> and(ind_id  like concat(\"%\", #{keywords}\"%\") OR ind_name like concat(\"%\", #{keywords}\"%\")  OR admin_name like concat(\"%\", #{keywords}\"%\") )" +
            "</if>"+
            "</script>"
      )
    List<Map<String,Object>> find_keyword(@Param("keywords") String keywords, @Param("model_name") String model_name);


//
//    @DataSource(DataSourceEnum.DB1)
//    @Select("SELECT COUNT(*)\n" +
//            "  FROM ${tableId} \n" +
//            "WHERE ind_id = #{ind_id}")
//    List<Map<String,Object>> table(@Param("tableId") String tableId, @Param("ind_id") String ind_id);










}
